import { getCurrent } from "./day";
import { onBeforeUnmount, onMounted, ref } from "vue";
export default () => {
  let timer = null;
  const curDate = ref(""),
    curTime = ref(""),
    carWeek = ref("");
  function setRealTime() {
    const { date, time, week } = getCurrent();
    curDate.value = date;
    curTime.value = time;
    carWeek.value = week;
  }
  function init() {
    setRealTime();
    timer = setInterval(() => {
      setRealTime();
    }, 1000);
  }
  onMounted(() => {
    init();
  });
  onBeforeUnmount(() => {
    clearInterval(timer);
  });
  return {
    curDate,
    curTime,
    carWeek,
  };
};
